import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/TS.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/space.dart';
import 'package:huajianshe_app/pages/circle/model/CircleModel.dart';
import 'package:huajianshe_app/pages/user_info/model/UserModel.dart';
import 'package:huajianshe_app/widget/AvatarWidget.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';

class UserInfoItem extends StatelessWidget {

  final UserInfo? userInfo;
  final EdgeInsets padding;
  final String time;
  final CircleInfo? circleInfo; //如果是从推荐列表点击的头像，进入个人主页后，发送请求需要带上圈子的信息

  UserInfoItem(this.userInfo, this.circleInfo, {Key? key,
    this.padding = const EdgeInsets.all(0),
    this.time = ''
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(padding: padding, child:
      Row(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start, children: [
        GestureDetector(onTap: () { userInfoPage(context); }, child:
          // userInfo?.isCaptain == 1 ? //圈主
          //   RoundedCornerWidget(width: 40, height: 40, radius: 20, padding: EdgeInsets.all(1.5), child:
          //     LoadImage.circleAvatar(userInfo?.avatar ?? '', 20, holderImg: 'placeholder'), backgroundColor: Colors.white, borderWidth: 1, borderColor: C.primary,
          //   )
          //     :
          //   RoundedCornerWidget(width: 40, height: 40, radius: 20, padding: EdgeInsets.all(0), child:
          //     LoadImage(userInfo?.avatar ?? '', holderImg: 'placeholder'), backgroundColor: Colors.transparent, borderWidth: 0, borderColor: Colors.transparent,
          //   )
          AvatarWidget(userInfo?.avatar, 40, 1.5, userInfo?.isCaptain)
          ,
        ),
        W(8),
        Expanded(child: Column(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start, children: [
          Row(mainAxisSize: MainAxisSize.max, children: [
            GestureDetector(onTap: () { userInfoPage(context); }, child:
              Text('${userInfo?.nickname}', style: TS(15, C.gray333))
            ),
            W(7),
            if (userInfo?.isCaptain == 1)
              RoundedCornerWidget(width: 32, height: 14, radius: 3, child: Center(child: Text('圈主', style: TS(10, Colors.white))),
                backgroundColor: Colors.transparent, borderWidth: 0, borderColor: Colors.transparent,
                gradient: LinearGradient(colors: [Color(0xFFFE2E2E), Color(0xFFF78C58)], begin: Alignment.topCenter, end: Alignment.bottomCenter),
              ),
            Spacer(),
            if (time.isNotEmpty) Text('$time', style: TS(12, C.gray999))
          ]),
          H(3),
          Text('${userInfo?.companyName}${userInfo?.positionName}', style: TS(12, C.gray666))
        ]))
      ]),

    );
  }

  void userInfoPage(BuildContext context) {
    print('userInfo: ${circleInfo}');
    if (userInfo?.isSelf == 1) { // 无法查看自己
      print('is me');
      return;
    }
    AppNavigator.push(context, RouteName.USER_INFO, arguments: {'userInfo': userInfo, 'circleInfo': circleInfo});
  }
}